<%-- 
    Document   : list
    Created on : 6-dec-2009, 15:23:53
    Author     : Simon
--%>

<%-- ${pageContext.request.contextPath} --%>
<%@include file="../header.jsp" %>

<%@page import="be.ugent.medirem.persistence.util.DateFormatter" %>


<h1>Patients of ${gpName}</h1>

<c:if test="${!empty flash}">
    <div class="flash notice">${flash}</div>
</c:if>


<form action="" onsubmit="return false;" id="search_patient" class="search">
    <input type="text" id="query" name="query" size="50" value="${query}"/>
    <%--<input type="submit" name="submit" value="Search" />--%>
</form>

<table class="data">
    <thead>
        <tr>
            <td>Name</td>
            <td>SSN</td>
            <td>Date of birth</td>
            <td>Bloodgroup</td>
            <td>Last consultation</td>
            <td>Next consultation</td>
            <td></td>
        </tr>
    </thead>
    <tbody>
        <c:forEach var="patient" items="${patients}">

            <tr>
                <td class="patient_name">${patient.surname} ${patient.firstname}</td>
                <td>${patient.socialSecurityNumber}</td>
                <td>
                    <fmt:formatDate value="${patient.birthDate}" type="both" pattern="dd MMM yyyy" />
                </td>
                <td>${patient.bloodgroup}</td>
                <td>
                    <fmt:formatDate value="${patient.lastConsultation}" pattern="dd MMM yyyy HH:mm" />
                </td>
                <td>
                    <fmt:formatDate value="${patient.nextConsultation}" pattern="dd MMM yyyy HH:mm" />
                </td>
                <td><a href="${pageContext.request.contextPath}/gp/patient/select?id=${patient.patientId}">Select</a></td>
            </tr>
        </c:forEach>
    </tbody>
</table>
<a href="${pageContext.request.contextPath}/gp/patient/new" class="add add_patient">Add a new patient</a>


<script type="text/javascript">
    $(document).ready(function(){
        var search_text = "Type to search a patient";
        var input = $("#search_patient #query");
        init_input_field(input, search_text, "#888");

        var display_row = $("td.patient_name").parent().css("display");
        if (!display_row)
            display_row = "table-row";
        input.keyup(function() {
            if (input.val() == search_text || input.val() == "") {
                jQuery.each($("td.patient_name"), function(index, item) {
                    $(item).parent().css("display",display_row);
                });
            };
            jQuery.each($("td.patient_name"), function(index, item) {
                if ($(item).text().toLowerCase().match(new RegExp(input.val().toLowerCase())))
                    $(item).parent().css("display",display_row);
                else
                    $(item).parent().css("display","none");
            });
        });
        
    });
</script>

<%@include file="../footer.jsp" %>
